//
//  YWInspectionMissionModel.m
//  maintain
//
//  Created by Kyo on 16/5/25.
//  Copyright © 2016年 ewin. All rights reserved.
//

#import "YWInspectionMissionModel.h"
#import "MJExtension.h"
#import "YWInspectionLineRecord.h"
#import "YWCommonTool.h"
#import "YWLocation.h"
#import "YWHandler.h"
#import "YWBuilding.h"

@implementation YWInspectionLineLocationRel
- (void)mj_keyValuesDidFinishConvertingToObject
{
    if (self.location) {
        self.locationId = self.location.locationId;
    }
}
@end

@implementation YWInspectionLineWeekRel
@end

@implementation YWInspectionLineModel
+ (NSDictionary*)mj_objectClassInArray
{
    return @{@"equipments" : @"YWEquipment",
             @"locationRels" : @"YWInspectionLineLocationRel",
             @"weekRels" : @"YWInspectionLineWeekRel"};
}
@end

@implementation YWInspectionMissionModel
+ (NSDictionary*)mj_objectClassInArray
{
    return @{@"executors" : @"YWHandler",
             @"observers" : @"YWHandler"};
}
+ (NSArray *)mj_ignoredPropertyNames
{
    return @[@"observerIds",@"currentLooperTimeArray",@"uniqueTag"];
}
- (void)mj_keyValuesDidFinishConvertingToObject{
    self.endDate += 86399000;//(23＊60*59+59)*1000
//    if (self.inspectionLine) {
//        self.latestRecord.inspectionLineId = self.inspectionLine.inspectionLineId;
//    }
//    if (self.executors) {
//        self.latestRecord.executors = self.executors;
//        self.latestRecord.executorIds = [YWCommonTool handlerIdsWithHandlerArray:self.executors];
//    }
    NSMutableString *atUserName = [[NSMutableString alloc] init];
    [self.observers enumerateObjectsUsingBlock:^(YWHandler*  _Nonnull handler, NSUInteger idx, BOOL * _Nonnull stop) {
        if (atUserName.length && idx!=0) {
            [atUserName appendString:@","];
        }
        [atUserName appendString:[@(handler.uniqueId) stringValue]];
    }];
    self.observerIds = [NSString stringWithFormat:@"%@",atUserName];
    if (self.building) {
        self.buildingId = self.building.buildingId;
    }
}
@end
@implementation YWInspectionLineOption
+ (NSDictionary *)mj_replacedKeyFromPropertyName{
    return @{@"inspectionLineId" : @"id",
             @"inspectionLineName" : @"text"};
}
@end
